/*/
 * An implementation of the SyncedTasksQueue interface.
 */

#include "SyncedTasksQueue.h"
#include <iostream>
#include <limits>

using namespace std;


void SyncedTasksQueue::pushTask(Task* task){
	pthread_mutex_lock(&_queueMutex);
	_tasks.push(task);
	pthread_mutex_unlock(&_queueMutex);
}


Task* SyncedTasksQueue::popTask(){
	//Getting hold of the lock needed for accessing the queue:
	pthread_mutex_lock(&_queueMutex);
	Task* temp = _tasks.front();
	_tasks.pop();
	pthread_mutex_unlock(&_queueMutex);
	return temp;
}


bool SyncedTasksQueue::empty(){
	pthread_mutex_lock(&_queueMutex);
	bool result = _tasks.empty();
	pthread_mutex_unlock(&_queueMutex);
	return result;
}
